When we desire a communication between two applications possibly running on different machines, we need sockets. This presentation aims to provide knowledge of basic socket programming to undergraduate students. Basically, this presentation gives the importance of socket in the area of networking and Unix Programming. The presentation of Topic (Sockets) has designed according to the Network Programming Subject, B.Tech, 6th Semester syllabus of Punjab Technical University Kapurthala, Punjab.
The overview on Socket Programming that will lead you how to program with a short example of programming which is in slide. With the help of this you can understand about network programming.
What is Socket Programming in Python | EdurekaEdureka!
YouTube Link: https://youtu.be/T0rYSFPAR0A
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Socket Programming in Python' is to educate you as to how networks are created using the socket module in Python. Below are the topics covered in this PPT:
What are sockets?
How to achieve socket programming in Python?
Servers and clients
Client-server communication
Transferring Python objects
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
When we desire a communication between two applications possibly running on different machines, we need sockets. This presentation aims to provide knowledge of basic socket programming to undergraduate students. Basically, this presentation gives the importance of socket in the area of networking and Unix Programming. The presentation of Topic (Sockets) has designed according to the Network Programming Subject, B.Tech, 6th Semester syllabus of Punjab Technical University Kapurthala, Punjab.
The overview on Socket Programming that will lead you how to program with a short example of programming which is in slide. With the help of this you can understand about network programming.
What is Socket Programming in Python | EdurekaEdureka!
YouTube Link: https://youtu.be/T0rYSFPAR0A
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Socket Programming in Python' is to educate you as to how networks are created using the socket module in Python. Below are the topics covered in this PPT:
What are sockets?
How to achieve socket programming in Python?
Servers and clients
Client-server communication
Transferring Python objects
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Webinar topic: Socket Programming with Python
Presenter: Achmad Mardiansyah
In this webinar series, Socket Programming with Python
Please share your feedback or webinar ideas here: http://bit.ly/glcfeedback
Check our schedule for future events: https://www.glcnetworks.com/en/schedule/
Follow our social media for updates: Facebook, Instagram, YouTube Channel, and telegram also discord
Recording available on Youtube
https://youtu.be/KtR4mIGnRNY
This presentation educates you about Python - Network Programming, What are Sockets?, Sockets have their own vocabulary, The socket Module, Server Socket Methods, Client Socket Methods and General Socket Methods.
For more info stay tuned with Learnbay.
A simple introduction to network programming using Python 3 socket module. This material was used in a 2-day summer training at Mansoura University in August 2016.
The examples included come from other tutorials with some changes. The source code of these and other examples can be found here:
https://github.com/ksonbol/socket_examples
Overview of the TFTP protocol.
TFTP (Trivial File Transfer Protocol) is, as its name implies, a very simple mechanism for transferring files between 2 hosts.
TFTP is typically used for downloading software and configuration files to Internet and LAN appliances like routers, switches and gateways.
Due to its simplicity, TFTP is often contained in bootloader programs that need to have a very small memory footprint in order to fit into EEPROM style chips.
TFTP is not a reduced version or predecessor of FTP. TFTP and FTP do not have anything in common and serve different purposes. While FTP comes with some minimal access and session control and other features, TFTP is barely a file transport mechanism.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
Webinar topic: Socket Programming with Python
Presenter: Achmad Mardiansyah
In this webinar series, Socket Programming with Python
Please share your feedback or webinar ideas here: http://bit.ly/glcfeedback
Check our schedule for future events: https://www.glcnetworks.com/en/schedule/
Follow our social media for updates: Facebook, Instagram, YouTube Channel, and telegram also discord
Recording available on Youtube
https://youtu.be/KtR4mIGnRNY
This presentation educates you about Python - Network Programming, What are Sockets?, Sockets have their own vocabulary, The socket Module, Server Socket Methods, Client Socket Methods and General Socket Methods.
For more info stay tuned with Learnbay.
A simple introduction to network programming using Python 3 socket module. This material was used in a 2-day summer training at Mansoura University in August 2016.
The examples included come from other tutorials with some changes. The source code of these and other examples can be found here:
https://github.com/ksonbol/socket_examples
Overview of the TFTP protocol.
TFTP (Trivial File Transfer Protocol) is, as its name implies, a very simple mechanism for transferring files between 2 hosts.
TFTP is typically used for downloading software and configuration files to Internet and LAN appliances like routers, switches and gateways.
Due to its simplicity, TFTP is often contained in bootloader programs that need to have a very small memory footprint in order to fit into EEPROM style chips.
TFTP is not a reduced version or predecessor of FTP. TFTP and FTP do not have anything in common and serve different purposes. While FTP comes with some minimal access and session control and other features, TFTP is barely a file transport mechanism.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docxmydrynan
CSc3320 Assignment 6 Due on 24th April, 2013
Socket programming code (server.c & client.c) demoed in class implement a server-client communication by socket. The server sets up a socket and waits for communication request from a client. The client tries to connect to server and asks user for a message to send to server after the connection established. Server then accepts the communication, reads the message, displays it and send confirmation message to the client. The client reads confirmation from server and displays it too.
Please modify the server.c such that the server can carry out the same communication with
3
clients. It creates a child process (fork()) every time a communication request from one client arrives and continues to wait to serve the next client. This child process takes care of reading message/sending confirmation from/to the corresponding client and terminates with the exit code 0. After serving all 3 clients, the server needs to accept (wait()) termination of all child processes it created. Server prints out message about the child process ID and the exit code every time it accepts the termination of a child process (eg. “A child with PID 1959 terminated with exit code 0”).
Client.c
#include
#include
#include
#include
#include
#include
#include
#include
void error(const char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc < 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
//printf("h_addr: %s\n", inet_ntoa(serv_addr.sin_addr));
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
error("ERROR writing to socket");
bzero(buffer,256);
n = read(sockfd,buffer,255);
if (n < 0)
error("ERROR reading from socket");
printf("%s\n",buffer);
close(sockfd);
return 0;
}
Server.c
/* A simple server in the internet domain using TCP
The port number is passed as an argument */
#include
#include
#include
#include
#include
#include
#include
#include
void error(const char *msg)
{
perror(msg);
.
Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems.
Introduction
This Tutorial is On Socket Programming In C Language for Linux. Instructions Give Below will only work On Linux System not in windows.
Socket API In windows is called Winsock and there we can discuss about that in another tutorial.
What is Socket?
Sockets are a method for communication between a client program and a server program in a network.
A socket is defined as "the endpoint in a connection." Sockets are created and used with a set of programming requests or "function calls" sometimes called the sockets application programming interface (API).
The most common sockets API is the Berkeley UNIX C interface for sockets.
Sockets can also be used for communication between processes within the same computer.
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIVladimir Iglovikov, Ph.D.
Presented by Vladimir Iglovikov:
- https://www.linkedin.com/in/iglovikov/
- https://x.com/viglovikov
- https://www.instagram.com/ternaus/
This presentation delves into the journey of Albumentations.ai, a highly successful open-source library for data augmentation.
Created out of a necessity for superior performance in Kaggle competitions, Albumentations has grown to become a widely used tool among data scientists and machine learning practitioners.
This case study covers various aspects, including:
People: The contributors and community that have supported Albumentations.
Metrics: The success indicators such as downloads, daily active users, GitHub stars, and financial contributions.
Challenges: The hurdles in monetizing open-source projects and measuring user engagement.
Development Practices: Best practices for creating, maintaining, and scaling open-source libraries, including code hygiene, CI/CD, and fast iteration.
Community Building: Strategies for making adoption easy, iterating quickly, and fostering a vibrant, engaged community.
Marketing: Both online and offline marketing tactics, focusing on real, impactful interactions and collaborations.
Mental Health: Maintaining balance and not feeling pressured by user demands.
Key insights include the importance of automation, making the adoption process seamless, and leveraging offline interactions for marketing. The presentation also emphasizes the need for continuous small improvements and building a friendly, inclusive community that contributes to the project's growth.
Vladimir Iglovikov brings his extensive experience as a Kaggle Grandmaster, ex-Staff ML Engineer at Lyft, sharing valuable lessons and practical advice for anyone looking to enhance the adoption of their open-source projects.
Explore more about Albumentations and join the community at:
GitHub: https://github.com/albumentations-team/albumentations
Website: https://albumentations.ai/
LinkedIn: https://www.linkedin.com/company/100504475
Twitter: https://x.com/albumentations
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfMalak Abu Hammad
Discover how MongoDB Atlas and vector search technology can revolutionize your application's search capabilities. This comprehensive presentation covers:
* What is Vector Search?
* Importance and benefits of vector search
* Practical use cases across various industries
* Step-by-step implementation guide
* Live demos with code snippets
* Enhancing LLM capabilities with vector search
* Best practices and optimization strategies
Perfect for developers, AI enthusiasts, and tech leaders. Learn how to leverage MongoDB Atlas to deliver highly relevant, context-aware search results, transforming your data retrieval process. Stay ahead in tech innovation and maximize the potential of your applications.
#MongoDB #VectorSearch #AI #SemanticSearch #TechInnovation #DataScience #LLM #MachineLearning #SearchTechnology
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Maruthi Prithivirajan, Head of ASEAN & IN Solution Architecture, Neo4j
Get an inside look at the latest Neo4j innovations that enable relationship-driven intelligence at scale. Learn more about the newest cloud integrations and product enhancements that make Neo4j an essential choice for developers building apps with interconnected data and generative AI.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
12. Programming TCP Client in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr,"usage %s hostname port", argv[0]); exit(0); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0) error("ERROR opening socket"); /* a structure to contain an internet address defined in the include file <netinet/in.h> */ struct sockaddr_in { short sin_family; /* should be AF_INET */ u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; /* not used, must be zero */ }; struct in_addr { unsigned long s_addr; }; Client.c
13. Programming TCP Client in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr,"usage %s hostname port", argv[0]); exit(0); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0) error("ERROR opening socket"); Client.c Socket System Call – create an end point for communication #include <sys/types.h> #include <sys/socket.h> int socket(int domain , int type , int protocol ); Returns a descriptor domain : selects protocol family e.g. PF_IPX, PF_X25, PF_APPLETALK type : specifies communication semantics e.g. SOCK_DGRAM, SOCK_RAW protocol : specifies a particular protocol to be used e.g. IPPROTO_UDP, IPPROTO_ICMP
14. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s",buffer); close(sockfd); return 0; } Client.c Connect System Call – initiates a connection on a socket #include <sys/types.h> #include <sys/socket.h> int connect( int sockfd , const struct sockaddr * serv_addr , socklen_t addrlen ); Returns 0 on success sockfd : descriptor that must refer to a socket serv_addr : address to which we want to connect addrlen : length of serv_addr
15. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s",buffer); close(sockfd); return 0; } Client.c Send System Call – send a message to a socket #include <sys/types.h> #include <sys/socket.h> int send( int s , const void * msg , size_t len , int flags ); Returns number of characters sent on success s : descriptor that must refer to a socket in connected state msg : data that we want to send len : length of data flags : use default 0. MSG_OOB, MSG_DONTWAIT
16. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s",buffer); close(sockfd); return 0; } Client.c Recv System Call – receive a message from a socket #include <sys/types.h> #include <sys/socket.h> int recv( int s , const void * buff , size_t len , int flags ); Returns number of bytes received on success s : descriptor that must refer to a socket in connected state buff : data that we want to receive len : length of data flags : use default 0. MSG_OOB, MSG_DONTWAIT
17. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s",buffer); close(sockfd); return 0; } Client.c Close System Call – close a socket descriptor #include <unistd.h> int close( int s ); Returns 0 on success s : descriptor to be closed
18. Programming TCP Server in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, newsockfd, portno, clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; int n; if (argc < 2) { fprintf(stderr,"ERROR, no port provided"); exit(1); } sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); Server.c
19. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Bind System Call – bind a name to a socket #include <sys/types.h> #include <sys/socket.h> int bind( int sockfd , const struct sockaddr * serv_addr , socklen_t addrlen ); Returns 0 on success sockfd : descriptor that must refer to a socket serv_addr : address to which we want to connect addrlen : length of serv_addr
20. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Listen System Call – listen for connections on a socket #include <sys/types.h> #include <sys/socket.h> int listen( int s , int backlog ); Returns 0 on success s : descriptor that must refer to a socket backlog : maximum length the queue for completely established sockets waiting to be accepted addrlen : length of serv_addr
21. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Accept System Call – accepts a connection on a socket #include <sys/types.h> #include <sys/socket.h> int accept( int sockfd , const struct sockaddr * addr , socklen_t addrlen ); Returns a non-negative descriptor on success sockfd : descriptor that must refer to a socket addr : filled with address of connecting entity addrlen : length of addr